package cool.tenyears.service.impl;

import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cool.tenyears.common.constant.MenuConstant;
import cool.tenyears.domain.Menu;
import cool.tenyears.mapper.MenuMapper;
import cool.tenyears.service.MenuService;
import cool.tenyears.util.TreeBuild;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tenyears
 * @date 2021/6/29 12:36
 */
@Service
@RequiredArgsConstructor
public class MenuServiceImpl implements MenuService {
    private final MenuMapper menuMapper;

    /**
     * 查询菜单树
     * @param menu 菜单
     * @return tree
     */
    @Override
    public List<Tree<String>> treeMenu(Menu menu) {
        List<Menu> menuList = menuMapper.selectList(Wrappers.emptyWrapper());
        return TreeBuild.build(menuList, MenuConstant.EXTRA_FIELD_ARR);
    }
}
